package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.articleDto.ArticleDto;
import com.heima.model.article.articleDto.ArticleHomeDto;
import com.heima.model.article.contants.ArticleContants;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author shitou
 * @className ArticleHomeController app端文章查看
 * @description: TODO
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/article")
public class ArticleHomeController {

    @Resource
    private ApArticleService articleService;

    /**
     * 文章首页加载
     *
     * @param articleHomeDto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto articleHomeDto) {
        log.info("文章首页加载");
        //return articleService.load(articleHomeDto, ArticleContants.LOAD_TYPE_MORE);
        return articleService.load2(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE,true);
    }

    /**
     * 加载更多
     *
     * @param articleHomeDto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto articleHomeDto) {
        log.info("文章加载更多");
        return articleService.load(articleHomeDto, ArticleContants.LOAD_TYPE_MORE);
    }

    /**
     * 加载最新
     *
     * @param articleHomeDto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto articleHomeDto) {
        log.info("文章加载最新");
        return articleService.load(articleHomeDto, ArticleContants.LOAD_TYPE_NEW);
    }

    /**
     * 文章保存
     *
     * @param articleDto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto articleDto) {

        return articleService.saveArticle(articleDto);
    }

}
